package org.arroganz.kapa.framework;

import java.awt.Graphics;

import javax.swing.JPanel;

public class MyCanvas extends JPanel{
	
//	private boolean runs = false;
//	private boolean isFirst = true;
	
	@Override
	public void paintComponent(Graphics g){
		
		super.paintComponent(g);
		
		System.out.println("start paint");
		paintY(g);
		paintX(g);
		paintCenter(g);
		System.out.println("end paint");
		
//		if(isFirst == true){
//			System.out.println("int paint in is");
//			isFirst = false;
//		}
//		
//		else{
//			System.out.println("int paint in else");
//			paintY(g);
//			paintX(g);
//		}
//		
//		System.out.println("in paint out if");
		// get all Rects method
		// set colors
		// etc
		// draw them
		// refresh method every 100 milli secs maby runable
		
	}
	
	private void getAllVisualData(){
		
	}
	
	private void setColor(){
		
	}
	
	private void paintCenter(Graphics g){
		
		int OrderLenght = getTimelineLenght(); // Rect summary in width
		int OrderHeight = getOrderSummary(); // Rect summary in height
		
		int RectX = 50; // width for one Rect (get this Value from Timeline Rects)
		int RectY = 50; // height for one Rect (get this from the Rects of Order)
		
		int x = 60;
		int y = 62;
		
		for (int i = 0; i < OrderHeight; i++) {
			for (int j = 0; j < OrderLenght; j++) {
				g.drawRect(x, y, RectX, RectY);
				x = x + 52;
			}
			x = 60;
			y = y + 52;
			System.out.println("height " + i);
			System.out.println("y " + y);
		}
		
	}

	public void paintY(Graphics g){
		
		int orderSummary = getOrderSummary();
		int y = 62;
		
		for (int i = 0; i < orderSummary; i++) {
			g.drawRect(5, y, 50, 50);
			y = y + 52;
		}
	}
	
	public void paintX(Graphics g){
		
		int timelineLenght = getTimelineLenght();
		int x = 60;
		
		for (int i = 0; i < timelineLenght; i++) {
			g.drawRect(x, 10, 50, 50);
			x = x + 52;
		}
		
	}
	
	public int getOrderSummary(){
		
		// Source
		
		return 20;
	}
	
	public int getTimelineLenght(){
		
		// Source
		
		return 50;
		
	}

//	@Override
//	public void run() {
//		
//		this.runs = true;
//		
//		System.out.println("in run");
//		
//		while(runs == true){
//			
//			System.out.println("in run in while");
//	
//			this.repaint();
//			
//			try {
//				Thread.sleep(5000);
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			
//		}
//		
//	}
	
}
